//-----------------------------------------------------------
//   Custom Interaction subclass to handle mouse clicking
//   and updates to player rotation
//
//   Unus
//-----------------------------------------------------------
//-----------------------------------------------------------
//
//-----------------------------------------------------------
class EnyaraMouseInteraction extends Interaction;


var vector mouse3D, wmouse3D;
var mouseTrailer trail;

function Initialized()
{
   Log("Interaction initialized");
}

/*function vector STW(vector loc)
{
   local vector stwLoc;

   stwLoc = ScreenToWorld(loc);

   return stwLoc;
}
*/

function bool KeyEvent( out EInputKey Key, out EInputAction Action, FLOAT Delta )
{
   local PlayerController PlayerOwner;
   local vector HitLocation, HitNormal, viewLoc;
   local rotator viewRot;
   local Actor HitActor;




   if( Action!=IST_Press )
      return false;
   else if( Key != IK_LeftMouse)
      return false;
   else if( Action == IST_Press )
   {
      PlayerOwner = ViewportOwner.Actor;

      if (PlayerOwner != none && PlayerOwner.Pawn != none) {
        //Use Player Pawn Location:
        viewLoc = PlayerOwner.Pawn.Location;
        viewRot = PlayerOwner.Pawn.Rotation;

        //Account for Pawn Height
        viewLoc.Z += PlayerOwner.Pawn.EyeHeight;

        //EnyaraPlayerController(PlayerOwner).doCursorTrace(HitLocation,HitNormal,HitActor);
        HitLocation = EnyaraPlayerController(PlayerOwner).HitLocation;
        HitNormal = EnyaraPlayerController(PlayerOwner).HitNormal;
        HitActor =  EnyaraPlayerController(PlayerOwner).HitActor;

        //PlayerOwner.DrawStayingDebugLine(viewLoc, HitLocation,255,0,0);

        //PlayerOwner.Pawn.setRotation(rotator(HitLocation-PlayerOwner.Pawn.Location));
        //newRot = rotator(HitLocation-PlayerOwner.Pawn.Location);
        //EnyaraPlayerController(PlayerOwner).changeRot(newRot);

        //EnyaraPlayerController(PlayerOwner).toRotate = true;

        //PlayerOwner.ClientMessage("Actor "@HitActor.Name@" has been hit at: "@HitLocation);

        //log("HitActor = (trace run here)" @HitActor);
        //log("traceStart = (location)" @traceStart@ " traceEnd = (traceStart + mouse3D * 5000)" @traceEnd);
      }
   }
   else if(Action == IST_Hold) {
      if (PlayerOwner.Pawn != none) {
        while(Action == IST_Hold) {
           PlayerOwner.Pawn.setRotation(rotator(HitLocation-PlayerOwner.Pawn.Location));
        }
      }
   }
   return false;
}

defaultproperties
{
     bVisible=True
}
